
********************************************************************************
**** Covid-19 Crisis and Hostility against Foreigners 
**** Data reshape from wide to long 
*******************************************************************************

log using "$logpath/01_data_reshape_wide_long", replace

***************************************************************************************************

{
use "$cleandatapath/covid_fuels_hostility_clean.dta", clear

keep respondentId region nQ63_2_1 nQ64_2_1 nQ65_2_1 nQ66_2_1 nQ67_2_1 nQ68_2_1 nQ69_2_1 nQ70_2_1 nQ71_2_1 nQ72_2_1 nQ73_2_1 nQ74_2_1 nQ75_2_1 nQ76_2_1 nQ77_2_1 nQ78_2_1 nQ79_2_1 covid_prime female age $basic_controls $additional_controls $endogenous_controls prague repre_weights end start attention_check1 attention_check2 educ CNP_hincome townsize  exp_time_min int_time_min attentive religion religion_help income_drop hworkdiffw1w0 hworkdiffw2w0 job_loss nQ51_1_1 payment_problems sav_monthandless sav_weeks happiness dep_anx pss4 nQ55_0_0 nQ55_1_0 nQ55_2_0 nQ55_3_0 nQ55_4_0 nQ55_5_0 nQ55_6_0 nQ55_7_0* activities_index not_working meeting_others order_A order_Bfirst order_B2first ///
med_nQ113_r1 med_nQ113_r2 med_nQ113_r3 med_nQ113_r4 med_nQ113_r5 med_nQ113_r6 med_nQ113_r7 med_nQ113_r8 med_nQ113_r9 med_nQ113_r10 med_nQ113_r11 med_nQ113_r12 med_nQ114_r1 med_nQ114_r2 med_nQ114_r3 med_nQ114_r4 social_media_high EU_referendum_positive EU_integration_positive institutions_covid_prime

rename nQ63_2_1 nQ63
rename nQ64_2_1 nQ64
rename nQ65_2_1 nQ65
rename nQ66_2_1 nQ66
rename nQ67_2_1 nQ67
rename nQ68_2_1 nQ68
rename nQ69_2_1 nQ69
rename nQ70_2_1 nQ70
rename nQ71_2_1 nQ71
rename nQ72_2_1 nQ72
rename nQ73_2_1 nQ73
rename nQ74_2_1 nQ74
rename nQ75_2_1 nQ75
rename nQ76_2_1 nQ76
rename nQ77_2_1 nQ77
rename nQ78_2_1 nQ78
rename nQ79_2_1 nQ79

reshape long nQ, i(respondentId) j(type_group)

label define type_group 63 "Region own (CZ)" 64 "Region different (CZ)" 65 "Prague (CZ)" 66 "Political own (CZ)" 67 "Political different (CZ)" 68 "Majority (CZ)" 69 "Roma (CZ)" 70 "CZ" 71 "Immigrant (CZ)" 72 "EU" 73 "USA" 74 "Africa" 75 "Asia" 76 "Atheist (CZ)" 77 "Christian (CZ)" 78 "Muslim (CZ)" 79 "Jew (CZ)" 
label values type_group type_group

* HHT groups
gen type_group2=""
replace type_group2="DOMESTIC" if type_group==70
replace type_group2="Asia" if type_group==75
replace type_group2="EU" if type_group==72
replace type_group2="USA" if type_group==73
replace type_group2="Africa" if type_group==74
replace type_group2="Region ingroup" if (type_group==63 | (prague==1 & type_group==65))
replace type_group2="Region outgroup" if (type_group==64 | (prague!=1 & type_group==65))
replace type_group2="Political ingroup" if type_group==66
replace type_group2="Political outgroup" if type_group==67
replace type_group2="Majority ingroup" if type_group==68
replace type_group2="Roma outgroup" if type_group==69
replace type_group2="Immigrant outgroup" if type_group==71
replace type_group2="Religion ingroup" if (religion_help==1 & type_group==76) | (religion_help==2 & type_group==77) | (religion_help==3 & type_group==78) | (religion_help==4 & type_group==79)  
replace type_group2="Religion outgroup" if (religion_help==1 & (type_group==77 | type_group==78 | type_group==79)) | (religion_help==2 & (type_group==76 | type_group==78 | type_group==79)) | (religion_help==3 & (type_group==76 | type_group==77 | type_group==79)) | (religion_help==4 & (type_group==76 | type_group==77 | type_group==78)) | (religion_help==5 & (type_group==76 | type_group==77 | type_group==78 | type_group==79))
replace type_group2="" if covid_prime==.

gen type_index=""
replace type_index="DOMESTIC" if type_group==70
replace type_index="FOREIGN" if (type_group==72 | type_group==73 | type_group==74 | type_group==75)
replace type_index="DOMESTIC ingroup" if (type_group==63 | (prague==1 & type_group==65) | type_group==66 | type_group==68 ) | ((religion_help==1 & type_group==76) | (religion_help==2 & type_group==77) | (religion_help==3 & type_group==78) | (religion_help==4 & type_group==79))
replace type_index="DOMESTIC outgroup" if (type_group==64 | (prague!=1 & type_group==65) | type_group==67 | type_group==69 | type_group==71) | ((religion_help==1 & (type_group==77 | type_group==78 | type_group==79)) | (religion_help==2 & (type_group==76 | type_group==78 | type_group==79)) | (religion_help==3 & (type_group==76 | type_group==77 | type_group==79)) | (religion_help==4 & (type_group==76 | type_group==77 | type_group==78)) | (religion_help==5 & (type_group==76 | type_group==77 | type_group==78 | type_group==79)))
replace type_index="" if covid_prime==.
label variable type_index "Recipient type (indexes) in the Help-or-Harm Task (recoded for analysis)"

rename type_group type_group_orig
rename type_group2 type_group
label variable type_group "Recipient type in the Help-or-Harm Task (recoded for analysis)"
label variable type_group_orig "Recipient type in the Help-or-Harm Task (original in questionnaire)"

rename nQ HHT
replace HHT=. if HHT==99999
*one value -1 --> ???
replace HHT=. if HHT==-1

label variable HHT "HHT allocation"

gen antisocial=HHT<100
replace antisocial=. if HHT==.
label variable antisocial "Hostile behavior (d)"
label values antisocial yes_no
gen altruistic=HHT>100
replace altruistic=. if HHT==.
label variable altruistic "Prosocial behavior (d)"
label values altruistic yes_no
gen stick_to_default=HHT==100
replace stick_to_default=. if HHT==.
label variable stick_to_default "Sticking to default allocation (d)"
label values stick_to_default yes_no


gen outgroup=.
replace outgroup=0 if  (type_index=="DOMESTIC" | type_index=="DOMESTIC ingroup" | type_group=="Region ingroup" | type_group=="Political ingroup" | type_group=="Majority ingroup" |type_group=="Religion ingroup") 
replace outgroup=1 if  (type_index=="FOREIGN" | type_group=="Asia" | type_group=="EU" | type_group=="USA"  | type_group=="Africa"  | type_index=="DOMESTIC outgroup" | type_group=="Region outgroup" | type_group=="Political outgroup" | type_group=="Roma outgroup" |type_group=="Immigrant outgroup " | type_group=="Religion outgroup" ) 
gen covid_outgroup=covid_prime*outgroup
label variable outgroup "Recipient in the Help-or-Harm Task is from an outgroup (d)"
label variable covid_outgroup "covid_prime*outgroup (d)"

gen inout_prime_help=1 if outgroup==0 & covid_prime==0
replace inout_prime_help=2 if outgroup==1 & covid_prime==0
replace inout_prime_help=3 if outgroup==0 & covid_prime==1
replace inout_prime_help=4 if outgroup==1 & covid_prime==1
label define inout_prime_help 1 "ingroup, no prime"  2 "outgroup, no prime" 3 "ingroup, covid prime" 4 "outgroup, covid prime"
label values inout_prime_help inout_prime_help




***************************************************************************************************
save "$cleandatapath/covid_fuels_hostility_clean_long.dta", replace
}

log close
